package com.WaVel.controller.admin;

import com.Emplyment.dto.CategoryDto;
import com.Emplyment.entity.EmplymentCategory;
import com.Emplyment.result.Result;
import com.WaVel.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 查询公司分类
     * @return
     */
    @GetMapping
    public Result<List<EmplymentCategory>> Category(){

        List<EmplymentCategory> categoryList = categoryService.SearchEmplymentCategoryAll();
        return Result.success(categoryList);

    }

    /**
     * 添加公司分类
     * @param categoryDto
     */
    @PostMapping
    public Result addCategory(@RequestBody CategoryDto categoryDto){
        categoryService.addEmplymentCategory(categoryDto);
        return Result.success();
    }


    @PutMapping
    public Result UpdataCategory(@RequestBody CategoryDto dto){
        categoryService.UpdataEmplymentCategory(dto);
        log.info("修改公司的id，名字，其它名为：{}{}{}",dto.getId(),dto.getCategoryName(),dto.getCategoryAlias());
        return Result.success();
    }


    @DeleteMapping
    @Transactional
    public Result DeleteCategory(@RequestParam int id){
        categoryService.DelectEmplymentCategory(id);
        log.info("删除的公司分类id为:{}",id);
        return Result.success();
    }
}
